package com.xhsj.user.hr.process.hrLeaveProcess.service;

import com.xhsj.user.hr.process.hrLeaveProcess.entity.TbHrApprovalLeaveTime;
import com.xhsj.user.hr.process.hrLeaveProcess.mapper.TbHrApprovalLeaveTimeMapper;
import com.xhsj.user.hr.process.hrLeaveProcess.query.LeaveTimeQuery;
import com.xhsj.user.hr.process.hrLeaveProcess.service.TbHrApprovalLeaveTimeService;
import com.xhsj.user.hr.base.BaseService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import com.xhsj.user.hr.system.vo.LeaveTimeVo;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;
import java.util.Collection;
import java.util.Map;
import java.util.Objects;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.io.Serializable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import lombok.extern.slf4j.Slf4j;
/**
 * <p>
 * 流程-hr请假时间表 服务实现类
 * </p>
 *
 * @author liuqinghua
 * @since Sep 1, 2020 10:09:59 AM
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
//@CacheConfig(cacheNames = "TbHrApprovalLeaveTime")
public class TbHrApprovalLeaveTimeService extends BaseService<TbHrApprovalLeaveTimeMapper, TbHrApprovalLeaveTime>{
    @Autowired
    private TbHrApprovalLeaveTimeMapper dao;

	/**
	 * 保存
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrApprovalLeaveTime", allEntries=true)
    public boolean save(TbHrApprovalLeaveTime entity) {
        return super.save(entity);
    }

	/**
	 * 通过id获取数据
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    @Override
    //@Cacheable(key = "#id",sync = true)
    public TbHrApprovalLeaveTime getById(Serializable id) {
        return super.getById(id);
    }

	/**
	 * 通过id删除数据
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    @Override
    //@CacheEvict(cacheNames="TbHrApprovalLeaveTime", allEntries=true)
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

	/**
	 * 批量删除数据
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    //@CacheEvict(cacheNames="SysDict", allEntries=true)
    @Override
    public boolean removeByIds(Collection<? extends Serializable> idList) {
        return super.removeByIds(idList);
    }

	/**
	 * 分页查询数据
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    //@Cacheable(key = "#data",sync = true)
    public IPage<TbHrApprovalLeaveTime> selectPage(Map<String,Object> data) {
        int currentPage=1;
        if (!Objects.isNull(data.get("page"))) {
            currentPage=(Integer) data.get("page");
        }
        int pageSize=20;
        if (!Objects.isNull(data.get("size"))) {
            pageSize=(Integer) data.get("size");
        }

        TbHrApprovalLeaveTime entity = JSON.parseObject(JSON.toJSONString(data), TbHrApprovalLeaveTime.class);
        Page<TbHrApprovalLeaveTime> page = new Page(currentPage,pageSize);
        QueryWrapper<TbHrApprovalLeaveTime> wrapper = new QueryWrapper(entity);
        return super.selectPage(page, wrapper);
    }

	/**
	 * 查询所有数据
	 * @author liuqinghua
	 * @date Sep 1, 2020 10:09:59 AM
	 */
    @Override
    //@Cacheable(value = "TbHrApprovalLeaveTime",sync = true)
    public List<TbHrApprovalLeaveTime> selectAll() {
        return super.selectAll();
    }


    /**
     * 请假申请时间
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public List<LeaveTimeQuery> getLeaveTimeList(List<Long> dataIdList,Long businessId) {
        return dao.getLeaveTimeList(dataIdList,businessId);
    }

    /**
     * 删除相对应的时间
     * @author liuqinghua
     * @date Sep 1, 2020 10:07:11 AM
     */
    public int deleteByDataId(Long dataId) {
        return dao.deleteByDataId(dataId);
    }




    /**
     * 根据开始时间和结束时间查询用户请假时间
     * @author 苏小林
     * @date 2020/11/5 10:28
     * @param: applyUserId
     * @param: monthStart
     * @param: monthEnd
     * @return: java.util.List<com.xhsj.user.hr.system.vo.LeaveTimeVo>
     */
    public List<LeaveTimeVo> getCurrentLeaveTimeByApplyUserId(Long applyUserId, LocalDate monthStart, LocalDate monthEnd) {
        return dao.getCurrentLeaveTimeByApplyUserId(applyUserId,monthStart,monthEnd);
    }
}
